﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Silvermoon.Core;
using Silvermoon.Windows;

namespace Silvermoon
{
    /// <summary>
    /// Chains multiple transformations together in a double linked list.
    /// </summary>
    internal class MultiTransformation : Transformation
    {
        private DblLinkedList<Transformation> list = new DblLinkedList<Transformation>();

        public bool IsEmpty { get { return list.IsEmpty; } }

        public override void Apply(Size size, ref Renderer.RenderData data)
        {
            DblLinkedNode<Transformation> end = list.End;
            DblLinkedNode<Transformation> node = end.Next;
            while (node != end)
            {
                node.Value.Apply(size, ref data);
                node = node.Next;
            }
        }

        public DblLinkedNode<Transformation> AddLast(Transformation t)
        {
            return list.AddLast(t);
        }

        public void Remove(Transformation t)
        {
            list.Remove(t);
        }

        public void Remove(DblLinkedNode<Transformation> node)
        {
            list.Remove(node);
        }

        public DblLinkedNode<Transformation> AddFirst(Transformation a)
        {
            return list.AddFirst(a);
        }

        public IEnumerable<Transformation> GetTransformations()
        {
            return list;
        }

        public override void AdjustBounds(ref Rectangle rect)
        {
            var node = list.First;
            var end = list.End;
            while (node != end)
            {
                node.Value.AdjustBounds(ref rect);
                node = node.Next;
            }
        }

    }
}
